import scrapy
from bossPro.items import BossproItem


class BossSpider(scrapy.Spider):
    name = 'boss'
    # allowed_domains = ['ww']
    start_urls = ['https://www.zhipin.com/c101020100-p100109']
    def detail_parse(self,response):
        item=response.meta['item']
        job_detail=response.xpath('//*[@id="main"]/div[3]/div/div[2]/div[2]/div[1]/div//text()').extract()
        job_detail=''.join(job_detail)
        item['job_detail']=job_detail
        yield item


    def parse(self, response):
        li_list=response.xpath('//*[@id="main"]/div/div[3]/ul/li')
        item=BossproItem()
        for li in li_list:
            job_name=li.xpath('./div/div[1]/div[1]/div/div[1]/span[1]/a/text()').extract_first()
            detail_url='https://www.zhipin.com'+li.xpath('.//span[@class="job-name"]/a/@href').extract_first()
            item['job_name']=job_name
            yield scrapy.Request(url=detail_url,callback=self.detail_parse,meta={'item':item})


